package com.yanqu.road.server.pb;

import com.yanqu.road.entity.activity.suitang.config.*;
import com.yanqu.road.entity.activity.tongbing.config.*;
import com.yanqu.road.entity.player.UserPatrons;
import com.yanqu.road.pb.activity.TongBingProto;
import com.yanqu.road.pb.activity.suitang.SuiTang;
import com.yanqu.road.server.manger.ServerLanguageMgr;
import com.yanqu.road.utils.date.DateHelper;

import java.util.ArrayList;
import java.util.List;

public class SuiTangPb {

    public static SuiTang.SuiTangConfigSync.Builder parseSuiTangSyncConfigRespMsg(SuiTangConfigSync config, String language) {
        SuiTang.SuiTangConfigSync.Builder builder = SuiTang.SuiTangConfigSync.newBuilder();
        for (SuiTangBuffConfig buffTypeConfig : config.getBuffConfigMap().values()) {
            builder.addBuff(SuiTangPb.parseSuiTangBuffTypeConfigMsg(buffTypeConfig, language));
        }
        for (SuiTangCityTypeConfig cityTypeConfig : config.getCityTypeConfigMap().values()) {
            builder.addCityType(SuiTangPb.parseSuiTangCityTypeConfigMsg(cityTypeConfig, language));
        }
        for (SuiTangCityConfig cityConfig : config.getCityConfigMap().values()) {
            builder.addCity(SuiTangPb.parseSuiTangCityConfigMsg(cityConfig, language));
        }
        for (SuiTangGuessConfig guessConfig : config.getGuessConfigMap().values()) {
            builder.addBet(SuiTangPb.parseSuiTangGuessConfigMsg(guessConfig, language));
        }
        for (SuiTangRankConfig rankConfig : config.getRankConfigMap().values()) {
            builder.addRank(SuiTangPb.parseSuiTangRankConfigMsg(rankConfig));
        }
        return builder;
    }

    public static SuiTang.SuiTangBuffConfig.Builder parseSuiTangBuffTypeConfigMsg(SuiTangBuffConfig config, String language) {
        SuiTang.SuiTangBuffConfig.Builder builder = SuiTang.SuiTangBuffConfig.newBuilder();
        builder.setId(config.getId());
        builder.setType(config.getType());
        builder.setIcon(config.getIcon());
        builder.setName(ServerLanguageMgr.getContent(config.getName(), language));
        builder.setDesc(ServerLanguageMgr.getContent(config.getDesc(), language));
        builder.setBuffEffect(config.getBuffEffect());
        builder.setContinueTime((int) (config.getContinueTime() / DateHelper.HOUR_MILLIONS));
        return builder;
    }

    public static SuiTang.SuiTangCityTypeConfig.Builder parseSuiTangCityTypeConfigMsg(SuiTangCityTypeConfig config, String language) {
        SuiTang.SuiTangCityTypeConfig.Builder builder = SuiTang.SuiTangCityTypeConfig.newBuilder();
        builder.setWarType(config.getWarType());
        builder.setType(config.getType());
        builder.setIcon(config.getIcon());
        builder.setName(ServerLanguageMgr.getContent(config.getName(), language));
        builder.setCampPoint(config.getCampPoint());
        builder.setFoodProduction((int)config.getFoodProduction());
        builder.setAddition(config.getAddition());
        builder.setBuffEffect(config.getBuffEffect());
        builder.setTeamNum(config.getTeamNum());
        builder.setSoldierNum(config.getSoldierNum());
        builder.setGeneralTeamNum(config.getGeneralTeamNum());
        builder.setGeneralSoldierNum(config.getGeneralSoldierNum());
        builder.setProtectTime(config.getProtectTime());
        builder.setDefenseMax(config.getDefenseMax());
        builder.setAttack(config.getAttack());
        builder.setFirstRecoverTeamNum(config.getFirstRecoverTeamNum());
        builder.setRecoverTeamNum(config.getRecoverTeamNum());
        return builder;
    }

    public static SuiTang.SuiTangCityConfig.Builder parseSuiTangCityConfigMsg(SuiTangCityConfig config, String language) {
        SuiTang.SuiTangCityConfig.Builder builder = SuiTang.SuiTangCityConfig.newBuilder();
        builder.setId(config.getId());
        builder.setName(ServerLanguageMgr.getContent(config.getName(), language));
        builder.setType(config.getType());
        builder.setShowType(config.getShowType());
        builder.setSoldierIcon(config.getSoldierIcon());
        builder.setSoldierName(ServerLanguageMgr.getContent(config.getSoldierName(), language));
        return builder;
    }

    public static SuiTang.SuiTangGuessConfig.Builder parseSuiTangGuessConfigMsg(SuiTangGuessConfig config, String language) {
        SuiTang.SuiTangGuessConfig.Builder builder = SuiTang.SuiTangGuessConfig.newBuilder();
        builder.setId(config.getId());
        builder.setName(ServerLanguageMgr.getContent(config.getName(), language));
        builder.setRewards(config.getRewards());
        return builder;
    }

    public static SuiTang.SuiTangRankConfig.Builder parseSuiTangRankConfigMsg(SuiTangRankConfig config) {
        SuiTang.SuiTangRankConfig.Builder builder = SuiTang.SuiTangRankConfig.newBuilder();
        builder.setId(config.getId());
        builder.setRound(config.getRound());
        builder.setRank(config.getRank());
        builder.setAward(config.getRewards());
        builder.setWarType(config.getWarType());
        return builder;
    }
}
